package com.zbkj.crmebadmin.controller;

import com.zbkj.crmebadmin.dto.ParamsDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("api/param")
@RestController
public class ParamController {
    @GetMapping("/url1")
    @ResponseBody             //不加的话，当成一个资源去寻找
    public String url1 (String param1,String param2) {
        System.out.println(param1+param2);
        return param1+param2;
    }

    @GetMapping("/url2")
    @ResponseBody
    public String url2 (@RequestParam(value = "paramA",defaultValue = "999") String param1, String param2) {
        System.out.println(param1+param2);
        return param1+param2;
    }

    @GetMapping("/url3")
    @ResponseBody
    public String url3 (ParamsDTO paramsDTO) {
        System.out.println(paramsDTO);
        return "teemo";
    }

    @PostMapping("/body1")
    @ResponseBody             //不加的话，当成一个资源去寻找
    public String body1 (String param1,String param2) {
        System.out.println(param1+param2);
        return param1+param2;
    }

    @PostMapping("/body2")
    @ResponseBody
    public String body2 (@RequestParam(value = "paramA",defaultValue = "999") String param1, String param2) {
        System.out.println(param1+param2);
        return param1+param2;
    }

    @PostMapping("/body3")
    @ResponseBody
    public String body3 (ParamsDTO paramsDTO, MultipartFile file) {
        System.out.println(paramsDTO);
        if(file != null){
           System.out.println(file.getSize());
        }
        return "teemo";
    }

    @PostMapping("/body4")
    @ResponseBody
    public String body4 (@RequestBody ParamsDTO paramsDTO) {
        System.out.println(paramsDTO);
        return "teemo";
    }

    @GetMapping("/header1")
    @ResponseBody
    public String header1 (@RequestHeader("Host") String host) {
       System.out.println(host);
       return host;
    }

    @GetMapping("/header2")
    @ResponseBody
    public String header1 (HttpServletRequest request) {
       String host = request.getHeader("Host");
        return host;
    }
    @GetMapping("/path/{id}")
    @ResponseBody
    public String path(@PathVariable String id) {
        System.out.println(id);
        return id;
    }

    public static void main(String[] args) {
       String str = "123";
       Integer num = Integer.valueOf(str);
    }
}
